package com.example.base.flow.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.base.excetion.GlobalExcetion;
import com.example.base.flow.domain.SysFlowTask;
import com.example.base.flow.mapper.SysFlowTaskMapper;
import com.example.base.flow.service.SysFlowTaskService;
import org.springframework.stereotype.Service;
import org.springframework.cache.annotation.*;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.cache.annotation.CacheConfig;

import java.io.Serializable;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author X.I.O
 * @since 2024-05-17
 */
@Service
@Transactional
@CacheConfig(cacheNames = "SysFlowTaskServiceImpl")
public class SysFlowTaskServiceImpl extends ServiceImpl<SysFlowTaskMapper, SysFlowTask> implements SysFlowTaskService {

    @Cacheable(cacheNames = "sysflowtask",key = "#id")
    @Override
    public SysFlowTask getById(Serializable id){
        return super.getById(id);
    }

    @CacheEvict(cacheNames = "sysflowtask", key = "#id")
    @Override
    public boolean removeById(Serializable id) {
        return super.removeById(id);
    }

    @CacheEvict(cacheNames = "sysflowtask", key = "#sysflowtask.id")
    @Override
    public boolean updateById(SysFlowTask sysflowtask) {
        return super.updateById(sysflowtask);
    }

    @CachePut(cacheNames = "sysflowtask", key = "#sysflowtask.id")
    public SysFlowTask saveSysFlowTask(SysFlowTask sysflowtask) throws GlobalExcetion {
        super.save(sysflowtask);
        return sysflowtask;
    }

    @CacheEvict(cacheNames = "sysflowtask", key = "#sysflowtask.id")
    public SysFlowTask updateSysFlowTaskById(SysFlowTask sysflowtask) throws GlobalExcetion{
        super.updateById(sysflowtask);
        return sysflowtask;
    }


    public IPage<SysFlowTask> page(Integer page, Integer pageSize) throws GlobalExcetion{
        LambdaQueryWrapper<SysFlowTask> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        IPage<SysFlowTask> iPage=super.baseMapper.selectPage(new Page<>(page,pageSize),lambdaQueryWrapper);
        return iPage;
    }
}
